import java.util.Map;

public class methods {

	public static void error(int index) { // prints the line where the first
											// line occurs and halts
		System.out.println("Error at line " + index);
		System.exit(0);
	}

	public static boolean checkPresence(String s, Map<String, Integer> reg, int index) {
		// checks if the given string is a key in the reg map if not it prints
		// an error
		if (reg.containsKey(s))
			return true;
		error(index);
		return false;
	}
	
	public static boolean checkMemo(String s, int index){
		// checks if string s is in the form n($t1)
		String[] l = s.split("[()]");
		if (l.length==2) return true;
		error(index);
		return false;
	}
	public static String[] getMemo(String s){
		//splits string s--> "n($t0)" and returns an array [n, $t0] 
		return s.split("[()]");
	}
	public static long unsigned(String s) {
		String concat = "";
		int n = 32 - s.length();
		char c = ' ';
		
		if (s.charAt(0) == '1')
			c = '1';
		else
			c = '0';
		
		for (int i = 0; i < n; i++)
			concat += c;
		
		return Long.parseLong(concat + s, 2);
	}

}
